package com.go8.sso.service;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.go8.sso.mapper.MemberAddressMapper;
import com.go8.sso.pojo.MemberAddress;

@Service
public class MemberAddressServiceImpl implements MemberAddressService {
	@Autowired
	private MemberAddressMapper memberAddressMapper;
	
	@Override
	public List<MemberAddress> getAddresses(long memberId) {
		return memberAddressMapper.selectByMemberId(memberId);
	}

	@Override
	public void add(MemberAddress address) {
		if(address.getYesDefault()) {
			MemberAddress address2 = memberAddressMapper.selectDefaultAddress();
			if(address2!=null) {
				address2.setYesDefault(false);
				memberAddressMapper.updateByPrimaryKey(address2);
			}
		}
		Date now = new Date();
		address.setGmtCreate(now);
		address.setGmtModified(now);
		memberAddressMapper.insertSelective(address);
	}

}
